﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ninject;
using Mabalacat.CPS.BusinessLogic.Services.Interfaces;
using Web.Codes;
using Mabalacat.CPS.DataAccess.DataObjects;

namespace Web.Admin
{
    public partial class ReportSignatory : System.Web.UI.Page
    {
        [Inject]
        public ISignatoryService _signatoryService { get; set; }
        
        public bool IsSuccess { get; set; }

        private Signatory signatory;
        public Signatory Signatory 
        {
            get { return signatory ?? _signatoryService.GetDefault(); }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Signatory != null)
                {
                    ClerkNameTxt.Text = Signatory.ClerkName;
                    ClerkPosTxt.Text = Signatory.ClerkName;
                    CertNameTxt.Text = Signatory.CertName;
                    CertPosTxt.Text = Signatory.CertPosition;
                    HeadNameTxt.Text = Signatory.HeadOfficialName;
                    HeadPosTxt.Text = Signatory.HeadOfficialPosition;
                    PayrollHeaderTxt.Text = Signatory.PayrollHeaderText;
                }
            }
        }

        protected void SubmitBtn_Click(object sender, EventArgs e)
        {                                   
            Signatory.ClerkName = ClerkNameTxt.Text;
            Signatory.ClerkName = ClerkPosTxt.Text;
            Signatory.CertName = CertNameTxt.Text;
            Signatory.CertPosition = CertPosTxt.Text;
            Signatory.HeadOfficialName = HeadNameTxt.Text;
            Signatory.HeadOfficialPosition = HeadPosTxt.Text;
            Signatory.PayrollHeaderText = PayrollHeaderTxt.Text;
                        
            _signatoryService.Update(Signatory);
            IsSuccess = _signatoryService.Save();
        }
    }
}